package com.eypg.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.eypg.pojo.User;
import com.eypg.service.UserService;
import com.eypg.util.StringUtil;
import com.eypg.util.Struts2Utils;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author 作者ryan_song E-mail:song316@gmai.com
 * @version 创建时间：2011-3-3 下午10:12:32
 * 类说明
 */
public class LoginAction extends ActionSupport{
	private static final long serialVersionUID = -6356307819518359036L;
	
	private String userName;
	private String pwd;
	private String message;
	
	@Autowired
	@Qualifier("userService")
	private UserService userService;
	
	public String login(){
		if(StringUtil.isBlank(userName)){
			message = "用户名或者密码错误!";
			return "error";
		}
		User user = userService.loadUserByName(userName);
		//只有网站工作人员能能登录后台.
		if(user!=null && user.getUserType()!=null && "1".equals(user.getUserType())){
			String password = user.getUserPwd();
			if(StringUtil.isNotBlank(password) && password.equals(pwd)){
				Struts2Utils.getSession().setAttribute("userName", userName);
				return "success";
			}else{
				message = "用户名或者密码错误!";
				return "error";
			}
		}else{
			message = "用户名或者密码错误!";
			return "error";
		}
	}
	
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPwd() {
		return pwd;
	}

	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
}
